"""Crafting systems helpers and default recipes."""

from __future__ import annotations

from dataclasses import dataclass
from typing import Mapping


@dataclass(frozen=True)
class Recipe:
    identifier: str
    name: str
    inputs: dict[str, int]
    outputs: dict[str, int]
    summary: str

    def can_craft(self, inventory: Mapping[str, int]) -> bool:
        return all(inventory.get(item, 0) >= amount for item, amount in self.inputs.items())


def build_default_recipes() -> list[Recipe]:
    return [
        Recipe(
            identifier="plank",
            name="木板",
            inputs={"wood": 1},
            outputs={"plank": 4},
            summary="1 木头 → 4 木板",
        ),
        Recipe(
            identifier="stone_brick",
            name="石砖",
            inputs={"stone": 2},
            outputs={"stone_brick": 1},
            summary="2 石头 → 1 石砖",
        ),
    ]


__all__ = ["Recipe", "build_default_recipes"]
